import 'package:flutter/material.dart';
import 'package:dio/dio.dart' show Dio;

import 'package:flutter_ume_kit_mock/widgets/icon.dart';
import 'package:flutter_ume_kit_mock/widgets/mock_state.dart';
import 'package:flutter_ume_kit_mock/network/mock_interceptor.dart';
import 'package:flutter_ume_kit_mock/data/mock_config_manager.dart';
import 'package:flutter_ume/core/pluggable_message_service.dart';
import 'package:flutter_ume/flutter_ume.dart';


class MockInspector extends StatefulWidget implements PluggableWithStream {
  static const String TAG = "Mock";

  final String feishuAppId;
  final String feishuAppSecret;

  MockInspector(
      {Key? key,
      required Dio? dio,
      required this.feishuAppId,
      required this.feishuAppSecret})
      : super(key: key) {
    dio?.interceptors.add(MockInterceptor());
    MockConfigManager.initConfigs(this.dio, feishuAppId, feishuAppSecret);
    //监听小红点
    PluginManager.instance.register(this);
    PluggableMessageService().resetListener();
  }

  late Dio dio = Dio();

  @override
  MockState createState() => MockState();

  @override
  ImageProvider<Object> get iconImageProvider => MemoryImage(iconBytes);

  @override
  String get name => 'Mock';

  @override
  String get displayName => 'Mock';

  @override
  void onTrigger() {
  }

  @override
  Widget buildWidget(BuildContext? context) => this;

  @override
  Stream get stream => MockConfigManager.triggerStreamController.stream;

  @override
  StreamFilter get streamFilter => (e) => true;
}
